#ifndef _IDATAGRAM_HPP_20120414
#define _IDATAGRAM_HPP_20120414

#include "base.hpp"
#include "streamer.hpp"

using namespace buffer;

namespace datagram
{
	class IDatagram 
	{
		public :
			const static uint32_t MAGIC         = 0x12133121;
			/// sizeof(_magic + _length + _type)
			const static uint32_t LENGTH        = sizeof(uint32_t) * 3;
			/// the offset of the _length member
			const static uint32_t  MAGIC_POS    = 0;
			const static uint32_t  LENGTH_POS   = sizeof(uint32_t);
			const static uint32_t  TYPE_POS     = sizeof(uint32_t) * 2;

		public :
			IDatagram(uint32_t type)
				: _magic(MAGIC),
				  _length(0),
				  _type(type)
			{
			}

			virtual ~IDatagram() {}

			uint32_t datagram_type() const { return _type; }

			virtual void serialize(Streamer & streamer)
				{
					streamer & _magic
						     & _length
							 & _type;
				}

			virtual std::string to_string() const
			{
				std::ostringstream oss;

				oss << "{magic: " << _magic
					<< ", length: " << _length
					<< ", type: " << _type
					<< "}";

				return oss.str();
			}

		public :
			uint32_t    _magic;
			uint32_t    _length;
			uint32_t    _type;
	};
};

#endif

